In Svelte, the $store syntax is a shorthand to automatically subscribe to a store and reactively access its current value inside a component. It eliminates the need to manually call the subscribe method and handle cleanup.
When you prefix a store with $ in a component, Svelte automatically subscribes to the store on component mount and unsubscribes on component destruction. The variable $store holds the current value of the store, and any updates to the store trigger reactive updates in the component.
You want automatic subscription and cleanup in a component.
You need reactive access to the store value for display or logic in templates.
You do not require custom side effects on store updates (otherwise, manual subscription is preferred).
Automatically subscribes and unsubscribes to stores—no manual cleanup needed.
Provides a reactive value in the component whenever the store updates.
Ideal for simple reactive UI updates; use manual subscription for custom side effects.
Works with writable, readable, and derived stores.